{literal}

<script>

function getAddForm(){
	var localeSectionsId = $('#sectionList').val();
	if (localeSectionsId != 0){
		$.ajax({
			type: "GET",
			url: "/locale/add-default",
			data: {
				localeSectionsId : localeSectionsId
			},
			success: function(data){
				showPopup(data, 'Add new default', false);
			},
			error: function(xhr, statusText, errorThrown){
				showPopup(xhr.responseText, statusText, false);
			}    
		
		});
	} else {
		alert('Please select localization section');
	}
}

function getEditForm(localeDefaultsId){
	
	$.ajax({
		type: "GET",
		url: "/locale/edit-default",
		data: {
			localeDefaultsId: localeDefaultsId
		},
		success: function(data){
			showPopup(data, 'Edit details', false);
		},
		error: function(xhr, statusText, errorThrown){
			showPopup(xhr.responseText, statusText, false);
		}    
	
	});
}

function getDefaults(){
	var localeSectionsId = $('#sectionList').val();
	if (localeSectionsId != 0){	
		$.ajax({
			type: "GET",
			url: "/locale/section-defaults",
			data: {
				localeSectionsId: localeSectionsId
			},
			success: function(data){
				$('#translationsBox').html(data);
				//showPopup(data, 'Edit details', false);
			},
			error: function(xhr, statusText, errorThrown){
				showPopup(xhr.responseText, statusText, false);
			}    
		
		});
	} else {
		alert('Please select localization section');
	}
}

function generateDefaults(){
	$.ajax({
		type: "GET",
		url: "/locale/generate-defaults",
		data: {
		},
		success: function(data){
			alert(data);
			//$('#translationsBox').html(data);
			//showPopup(data, 'Edit details', false);
		},
		error: function(xhr, statusText, errorThrown){
			showPopup(xhr.responseText, statusText, false);
		}    
	
	});
}

function deleteDefault(localeDefaultsId){
	if (confirm('Are you sure you want to remove this localization default?')){
		$.ajax({
			type: "GET",
			url: "/locale/delete-default",
			data: {
				localeDefaultsId: localeDefaultsId
			},
			success: function(data){
				//showPopup(data, 'Skinshop activation', false);
				//window.location.reload();
				getDefaults();
			},
			error: function(xhr, statusText, errorThrown){
				showPopup(xhr.responseText, statusText, false);
			}
	
		});
		
	}
	return false;
}
</script>

{/literal}

{strip}
<!-- content -->
<div id="content">
    <div id="content_left">

		<a class="button_" ref="#" onclick="getAddForm();">{$commonLocale->t('ADD NEW')}</a>&nbsp;&nbsp;<a class="button_" ref="#" onclick="generateDefaults();">Generate localization defaults files</a><br /><br />
	
		CHOOSE SECTION: 
			<select id="sectionList" onchange="getDefaults();" class="_button">
				<option value="0">--- ----</option>
				{foreach $sections as $k=>$v}
					<option value="{$v->getId()}">{$v->getSection()}</option>
				{/foreach}
			</select>
			<br />
			<div id="translationsBox"> </div>

	</div>
	<div id="content_right">
		{include file='admin/menu.tpl'}
	</div>
</div>
<!-- end content  -->
{/strip}